import {
  sessionStorage
} from "@/utils";
import {
  fetchGeneralizeSide
} from "@/api";
export default {
  namespaced: true,
  state: {
    data: []
  },
  mutations: {
    SET_NAV(state, value) {
      state.data = value;
    }
  },
  actions: {
    UPDATE_DATA({
      commit
    }) {
      fetchGeneralizeSide({
        query: {
          userId: sessionStorage.get("USER").userId
        }
      }).then(res => {
        let data = res.data.list;
        // 只有两层数据，第一层添加 icon: "iconfont-14"
        data.forEach(item => {
          item.icon = "iconfont iconfont-14";
          item.isActive = false;
          if (item.children && item.children.length) {
            item.children.forEach(child => {
              child.isActive = false;
            });
          }
        });
        commit("SET_NAV", [{
          name: "所有计划",
          icon: "iconfont iconfont-2",
          isActive: true,
          id: 0
        }].concat(data))
      });
    }
  }
}